package com.hulk.sequence;


import com.hulk.sequence.builder.SnowflakeSeqBuilder;
import com.hulk.sequence.sequence.Sequence;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author hulk
 * @date 2019-05-26
 */
@Configuration
public class SequenceAutoConfiguration {

	/**
	 * snowflak 算法作为发号器实现
	 * @param properties
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean
	public Sequence snowflakeSequence(SequenceProperties properties) {
		return SnowflakeSeqBuilder
				.create()
				.datacenterId(properties.getSnowflake().getDatacenterId())
				.workerId(properties.getSnowflake().getWorkerId())
				.build();
	}
}